// 迭代二分查找 时间复杂度 O(logn) 空间复杂度 O(1)

class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        int left = 0, right = nums.size() - 1, mid;
        while (left <= right) {
            mid = left + (right - left) / 2;
            if (left < mid && nums[mid - 1] > nums[mid]) {
                right = mid - 1;
            }
            else if (mid < right && nums[mid + 1] > nums[mid]) {
                left = mid + 1;
            }
            else {
                break;
            }
        }
        return mid;
    }
};